$(document).ready(function () {
    //弹框
    $('.modal-default').on('show.bs.modal', function (event) {
        var _modal = $(this);
        var button = $(event.relatedTarget);
        $('.model-confirm').unbind('click').click(function (e) {
            e.preventDefault();
            _modal.modal('hide');
            button.parents('td').find('.operate-div').hide();//隐藏操作按钮
            button.parents('td').find('.line-scale-pulse-out').show();//显示loading
            //模拟提交成功
            var timeOut = setTimeout(function () {
                button.parents('td').find('.line-scale-pulse-out').hide();//隐藏loading
                button.parents('td').find('.operate-div').show();//显示操作按钮
                //成功提示
                $.bootstrapGrowl("提交成功!", {
                    ele: 'body', // which element to append to
                    type: 'info', // (null, 'info', 'error', 'success')
                    offset: {from: 'top', amount: 350}, // 'top', or 'bottom'
                    align: 'center', // ('left', 'right', or 'center')
                    width: 250, // (integer, or 'auto')
                    delay: 1000000,
                    allow_dismiss: true,
                    stackup_spacing: 10 // spacing between consecutively stacked growls.
                });
            }, 1000);

        });
    });

    //主机、快照，切换
    $('#yunzhuji .yunzhuji-tab .tab-sub').click(function () {
        if ($(this).hasClass('active') == false) {
            $('#yunzhuji .yunzhuji-tab .tab-sub').removeClass('active');
            $(this).addClass('active');
            $('.yunzhuji-tabcontent .zhuji').toggle();
            $('.yunzhuji-tabcontent .kuaizhao').toggle();
        }
    });

    //全选
    $('.checkall').click(function () {
        if ($(this).is(':checked')) {
            $(this).parents('.table').find('input[type="checkbox"]').prop('checked', true);
        } else {
            $(this).parents('.table').find('input[type="checkbox"]').prop('checked', false);
        }
    });
    //忽略
    $('.ignore').click(function () {
        $(this).text('已忽略');
        $(this).addClass('link-none');
        $(this).addClass('color-unkonwn');
    });
    //云监控列表图标展示切换
    $('#yunjiankong .list-type.list').click(function () {
        $('#yunjiankong .list-type').hide();
        $('#yunjiankong .list-type.icon').show();
        $('#yunjiankong .list-result').hide();
        $('#yunjiankong .result-list').show();
    });
    $('#yunjiankong .list-type.icon').click(function () {
        $('#yunjiankong .list-type').hide();
        $('#yunjiankong .list-type.list').show();
        $('#yunjiankong .list-result').hide();
        $('#yunjiankong .result-icon').show();
    });
    //云监控图标展示全选
    $('#yunjiankong .yunjiankong-checkall').click(function () {
        if ($(this).is(':checked')) {
            $(this).parents('.result-icon').find('input[type="checkbox"]').prop('checked', true);
        } else {
            $(this).parents('.result-icon').find('input[type="checkbox"]').prop('checked', false);
        }
    });
    //图标按钮点击变色
    $('.modal').on('show.bs.modal', function (e) {
        var button = $(e.relatedTarget);
        button.addClass('active');
    });
    $('.modal').on('hide.bs.modal', function (e) {
        $('.operate').removeClass('active');
    });
});
//时间格式化
Date.prototype.Format = function (formatStr) {
    var str = formatStr;
    var Week = ['日', '一', '二', '三', '四', '五', '六'];

    str = str.replace(/yyyy|YYYY/, this.getFullYear());
    str = str.replace(/yy|YY/, (this.getYear() % 100) > 9 ? (this.getYear() % 100).toString() : '0' + (this.getYear() % 100));

    str = str.replace(/MM/, this.getMonth() > 9 ? this.getMonth() : '0' + this.getMonth());
    str = str.replace(/M/g, this.getMonth());

    str = str.replace(/w|W/g, Week[this.getDay()]);

    str = str.replace(/dd|DD/, this.getDate() > 9 ? this.getDate().toString() : '0' + this.getDate());
    str = str.replace(/d|D/g, this.getDate());

    str = str.replace(/hh|HH/, this.getHours() > 9 ? this.getHours().toString() : '0' + this.getHours());
    str = str.replace(/h|H/g, this.getHours());
    str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes().toString() : '0' + this.getMinutes());
    str = str.replace(/m/g, this.getMinutes());

    str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds().toString() : '0' + this.getSeconds());
    str = str.replace(/s|S/g, this.getSeconds());

    return str;
};
function getStartTime(date) {
    var timestamp = date.getTime();
    var newDate = new Date(timestamp);
    var startdate = [newDate.getFullYear(), newDate.getMonth() + 1, newDate.getDate()].join('-');
    return startdate;
}